% Read the JULIA 150 Km echo data, combine them

% June 17, 2011



S = dir('E:\projects\ace_tensor\juliadata\jro.igp.gob.pe\database\drifts\data\www_150\*.txt');

localdirectory = 'E:\projects\ace_tensor\juliadata\jro.igp.gob.pe\database\drifts\data\www_150\';

Julia_W = zeros([132,length(S)])'*NaN;
Julia_fday = Julia_W;

for i = 1:length(S),
        
    [data] = textread([ localdirectory S(i).name] ,'%f','delimiter',',','emptyvalue',NaN,'headerlines',6);
    
    data = reshape(data',[5,length(data)/5])';
        
    year = str2double(S(i).name(9:12));
    dayoftheyear = str2double(S(i).name(13:15));
    
    fday = datenum(year,1,0,data(:,1)+5,data(:,2),30) + dayoftheyear;
    %Hard writing 30 sec to tolerate small changes in time
    Julia_W(i,1:length(fday)) = data(:,4);
    Julia_fday(i,1:length(fday)) = fday;
    
    fprintf('%s %d\n',S(i).name,length(data));
    
    
end;

% Arrange the data according to the correct time stamps

Julia_W_n = zeros([132,length(S)])'*NaN;
Julia_fday_n = Julia_W_n;

ncount = 0;
jfday = Julia_fday(1,:)-floor(Julia_fday(1,:));
for i = 1:length(S),
    
    thisfday = Julia_fday(i,:)-floor(Julia_fday(i,:));
    [c,ia,ib] = intersect(jfday,thisfday);
    if ~isempty(c),
        Julia_W_n(i,ia) = Julia_W(i,ib);
        Julia_fday_n(i,ia) = Julia_fday(i,ib);
    else
        ncount = ncount + 1;
    end;
end;
    
save E:\projects\ace_tensor\juliadata\Julia_2001_2011 Julia_W_n Julia_fday_n;

    
    
    

